(function (G) {
    G.vue({
        data: {
            actioning: false,
            userInfo: '',
            logo: '',
            models: {
                userName: {
                    label: '手机号',
                    rule: {
                        NotNull: true
                    },
                    type: 'input',
                    attr: {
                        placeholder: '请输入手机号'
                    }
                },
                passWord: {
                    label: '密码',
                    rule: {
                        NotNull: true
                    },
                    type: 'input',
                    attr: {
                        type: 'password',
                        placeholder: '请输入登录密码'
                    }
                }
            },
            values: {}
        },
        methods: {
            auth: function (event) {
                var _this = this;
                if (this.getData('actioning')) return false;
                var data = this.selectComponent('#form').submit();
                if (!data) return false;
                data = G.merge(this.getData('values'), data);
                data.encryptedData = event.detail.encryptedData;
                data.iv = event.detail.iv;
                data.passWord = G.MD5(data.passWord)
                if (data.iv) {
                    this.setData({
                        actioning: true
                    });
                    G.post('/v1/auth', data).then(ret => {
                        _this.setData({
                            actioning: false
                        });
                        if (!ret.errorMsg) {
                            G.Storage.get('autoLogin')(function () {
                                G.alertx(ret.errorMsg || '登陆成功!', function () {
                                    // _this.$back();
                                    wx.reLaunch({
                                        url: '/pages/index/index',
                                    })
                                })
                            })
                        }
                    })
                }
            },
            doUserInfo: function () {
                wx.getUserProfile({
                    desc: '用于用户资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
                    success: (res) => {
                        this.setData({
                            userInfo: res.userInfo
                        })
                    }
                })
            },
            doPhoneNumber: function (event) {
                wx.checkSession({
                    success: (ret) => {
                        this.auth(event);
                    },
                    fail: (ret) => {
                        G.alertx('登录已失效，请再次点击!');
                        G.Storage.get('autoLogin')(function () {}, function () {})
                    }
                })
            }
        }
    })
})(wx.$)